package net.wanho.controller;

import com.wf.captcha.base.Captcha;
import lombok.RequiredArgsConstructor;
import net.wanho.dto.LoginUserDTO;
import net.wanho.service.CaptchaService;
import net.wanho.service.LoginService;
import net.wanho.vo.CaptchaVo;
import net.wanho.vo.LoginUserVo;
import net.wanho.vo.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author：汤小洋
 * Date：2025-01-12 15:25
 * Description：<描述>
 */
@RestController
@RequiredArgsConstructor
public class LoginController {

    private final CaptchaService captchaService;
    private final LoginService loginService;

    @GetMapping("/captchaImage")
    public R captchaImage(){
        CaptchaVo captchaVo = captchaService.captcha();
        return R.ok(captchaVo);
    }

    @PostMapping("/login")
    public R login(@RequestBody LoginUserDTO loginUserDTO){
        String token = loginService.login(loginUserDTO);
        return R.ok("登录成功", token);
    }

    @GetMapping("/curr-user")
    public R currUser(){
        LoginUserVo loginUserVo = loginService.getCurrentUser();
        return R.ok(loginUserVo);
    }
}
